package com.jxw.cloudpen.web.netty.handler;


import com.jxw.cloudpen.web.netty.Entity.StreamData;
import com.jxw.cloudpen.web.netty.client.NettyClientBootstrap;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.util.Attribute;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 接受登录结果
 * 登录成功切换心跳处理
 * 记录session
 */
@Slf4j
@ChannelHandler.Sharable
@Service("LoginResponceHandler")
public class LoginResponceHandler extends ChannelInboundHandlerAdapter {

    /**
     * 业务逻辑处理
     */
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg)
            throws Exception {
        //判断消息实例
        if (null == msg || !(msg instanceof StreamData)) {
            super.channelRead(ctx, msg);
            return;
        }
        //判断类型
        StreamData message = (StreamData) msg;
        if (1 !=message.getType()) {
            super.channelRead(ctx, msg);
            return;
        }
        NettyClientBootstrap.clientId = message.getClientId();
        ctx.channel().pipeline().remove("loginResponseHandler");
    }


}
